package com.xuexiang.xuidemo.slice.popupwindow;

import ohos.agp.components.Component;
import ohos.agp.components.DependentLayout;
import ohos.agp.components.TextField;
import ohos.agp.utils.Color;

import com.xuexiang.xui_lib.component.popupwindow.ViewTooltip;
import com.xuexiang.xuidemo.ResourceTable;
import com.xuexiang.xuidemo.slice.BaseAbilitySlice;
import com.xuexiang.xuidemo.util.XToastUtils;

public class ViewTipAbilitySlice extends BaseAbilitySlice {


    private DependentLayout layout;
    private TextField textField;
    private Component btnBottomLeft;
    private Component btnBottomRight;

    @Override
    protected int getUIContentLayoutId() {
        return ResourceTable.Layout_ability_popup_viewtip;
    }

    @Override
    protected int getTitleBarId() {
        return ResourceTable.Id_title_bar;
    }

    @Override
    protected void initComponents() {
        super.initComponents();
        layout = (DependentLayout) findComponentById(ResourceTable.Id_layout_view_tip);
        textField = (TextField) findComponentById(ResourceTable.Id_tv_content);
        btnBottomLeft = findComponentById(ResourceTable.Id_tv_bottom_left);
        btnBottomRight = findComponentById(ResourceTable.Id_tv_bottom_right);
        findComponentById(ResourceTable.Id_tv_left).setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                tipOnLeft();
            }
        });
        findComponentById(ResourceTable.Id_tv_right).setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                tipOnRight();
            }
        });
        findComponentById(ResourceTable.Id_tv_top).setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                tipOnTop();
            }
        });
        findComponentById(ResourceTable.Id_tv_bottom).setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                tipOnBotton();
            }
        });
        btnBottomLeft.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                tipOnBottomLeft();
            }
        });
        btnBottomRight.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                tipOnBottomRight();
            }
        });
    }

    public void tipOnLeft() {
        ViewTooltip
            .on(textField)
            .color(Color.BLACK)
            .position(ViewTooltip.Position.LEFT)
            .text("Some tooltip with long text")
            .clickToHide(true)
            .autoHide(false, 0)
            .animation(new ViewTooltip.FadeTooltipAnimation(500))
            .onDisplay(view12 -> XToastUtils.toast("onDisplay"))
            .onHide(view1 -> XToastUtils.toast("onHide"))
            .show(layout);
    }

    public void tipOnRight() {
        ViewTooltip
            .on(textField)
            .autoHide(true, 1500)
            .position(ViewTooltip.Position.RIGHT)
            .text("Some tooltip with long text")
            .show(layout);
    }

    public void tipOnTop() {
        ViewTooltip
            .on(textField)
            .position(ViewTooltip.Position.TOP)
            .text("Popup可以设置其位置以及显示和隐藏的动画")
            .show(layout);
    }


    public void tipOnBotton() {
        ViewTooltip
            .on(textField)
            .color(Color.BLACK)
//                .padding(20, 20, 20, 20)
            .position(ViewTooltip.Position.BOTTOM)
            .align(ViewTooltip.ALIGN.START)
            .text("abcdefg")
            .show(layout);
    }

    public void tipOnBottomRight() {
        ViewTooltip
            .on(btnBottomRight)
            .position(ViewTooltip.Position.TOP)
            .text("bottomRight bottomRight bottomRight")
            .show(layout);
    }

    public void tipOnBottomLeft() {
        ViewTooltip
            .on(btnBottomLeft)
            .position(ViewTooltip.Position.TOP)
            .text("bottomLeft bottomLeft bottomLeft")
            .show(layout);
    }

}
